<?php if (!defined('THINK_PATH')) exit();?><!DOCTYPE html>
                <html lang="zh-CN">
                <head>
                    <meta charset="utf-8">
                    <meta http-equiv="X-UA-Compatible" content="IE=edge">
                    <meta name="viewport" content="width=device-width, initial-scale=1">
                    <title>CMS管理系统</title>

                    <link href="/Public/bootstrap/css/bootstrap.min.css" rel="stylesheet">
                    <link rel="stylesheet" href="/Public/css/common.css">
                    
    <style>
        #page2 {
            display: none;
        }
    </style>

                </head>
                <body>

                <nav class="navbar navbar-default navbar-fixed-top col-md-10">
                    <div class="container-fluid nav_bg">
                        <!-- Brand and toggle get grouped for better mobile display -->
                        <div class="navbar-header">
                            <button type="button" class="navbar-toggle collapsed" data-toggle="collapse"
                                    data-target="#bs-example-navbar-collapse-1" aria-expanded="false">
                                <span class="sr-only">Toggle navigation</span>
                                <span class="icon-bar"></span>
                                <span class="icon-bar"></span>
                                <span class="icon-bar"></span>
                            </button>
                            <a class="navbar-brand" href="<?php echo U('Index/index');?>">首页</a>
                        </div>

                        <!-- Collect the nav links, forms, and other content for toggling -->
                        <div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
                            <ul class="nav navbar-nav">
                                <li class="active"><a href="#">Link <span class="sr-only">(current)</span></a></li>
                                <li><a href="<?php echo U('Link/index');?>">友情链接管理</a></li>
                                <li class="dropdown">
                                    <a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true"
                                       aria-expanded="false">前端文件管理 <span class="caret"></span></a>
                                    <ul class="dropdown-menu">
                                        <li><a href="<?php echo U('File/index');?>">文件管理</a></li>
                                        <li role="separator" class="divider"></li>
                                        <li><a href="<?php echo U('Article/show');?>">Finder</a></li>
                                    </ul>
                                </li>

                                <li class="dropdown">
                                    <a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true"
                                       aria-expanded="false">内容管理 <span class="caret"></span></a>
                                    <ul class="dropdown-menu">
                                        <li><a href="<?php echo U('Article/index');?>">文章列表</a></li>
                                        <li role="separator" class="divider"></li>
                                        <li><a href="<?php echo U('Category/index');?>">栏目管理</a></li>
                                    </ul>
                                </li>

                                <li class="dropdown">
                                    <a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true"
                                       aria-expanded="false"><span class="glyphicon glyphicon-cog" aria-hidden="true"></span> 系统设置 <span
                                            class="caret"></span></a>
                                    <ul class="dropdown-menu">
                                        <li><a href="<?php echo U('System/config');?>">站点信息</a></li>
                                        <li role="separator" class="divider"></li>
                                        <li><a href="<?php echo U('User/password_edit');?>">密码修改</a></li>
                                    </ul>
                                </li>

                            </ul>


                            <ul class="nav navbar-nav navbar-right">
                                <li><a href="<?php echo U('File/destroy_cache');?>">清除缓存</a></li>
                <li class="dropdown">
                    <a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true"
                       aria-expanded="false">尊敬的<?php echo ($user["username"]); ?> <span class="caret"></span></a>
                    <ul class="dropdown-menu">
                        <li><a href="#">Action</a></li>
                        <li><a href="#">Another action</a></li>
                        <li><a href="#">Something else here</a></li>
                        <li role="separator" class="divider"></li>
                        <li><a href="<?php echo U('User/logout');?>">安全退出</a></li>
                    </ul>
                </li>
            </ul>
        </div><!-- /.navbar-collapse -->
    </div><!-- /.container-fluid -->
</nav>

<div class="container-fluid">
    
    <div class="row">
        <div class="col-md-12">

            <div class="row">
                <div class="col-md-8">
                    <div class="page-header">
                        <h1>友情链接</h1>
                    </div>
                </div>
            </div>

            <div class="row">
                <div class="col-md-10">
                    <div class="panel panel-default">
                        <div class="panel-heading">Link Config</div>

                        <div class="panel-body">
                            <form action="" method="post" id="form">
                            <table class="table table-hover">
                                <thead>
                                <tr>
                                    <th><input type="checkbox" id="check_all"></th>
                                    <th>链接名称</th>
                                    <th>网址</th>
                                    <th>排序</th>
                                    <th>操作</th>
                                </tr>
                                </thead>
                                <tbody>


                                <?php if(is_array($links)): $i = 0; $__LIST__ = $links;if( count($__LIST__)==0 ) : echo "" ;else: foreach($__LIST__ as $key=>$link): $mod = ($i % 2 );++$i;?><tr>
                                        <th scope="row">
                                            <input type="checkbox" class="delete_checked" name="delete_ids[]" value="<?php echo ($link["id"]); ?>"></th>
                                        <td class="name"><?php echo ($link["name"]); ?></td>
                                        <td class="url"><?php echo ($link["url"]); ?></td>
                                        <td>
                                            <input type="hidden" name="ids[]" value="<?php echo ($link["id"]); ?>">
                                            <input type="text"  name="sort_order[]" value="<?php echo ($link["sort_order"]); ?>">
                                        </td>
                                        <td>
                                            <a href="" data-toggle="modal" data-target="#edit_link"
                                               data-id="<?php echo ($link["id"]); ?>" class="edit">
                                                <span class="glyphicon glyphicon-pencil" aria-hidden="true"></span>
                                            </a>
                                                <a href="<?php echo U('destroy',array('id'=>$link['id']));?>">
                                                <span class="glyphicon glyphicon-trash" aria-hidden="true"></span>
                                            </a>
                                        </td>
                                    </tr><?php endforeach; endif; else: echo "" ;endif; ?>


                                </tbody>
                            </table>
                            </form>


                        </div>
                    </div>
                </div>

                <div class="col-md-2">
                    <div class="list-group">
                        <a href="javascript: void 0;" class="list-group-item list-group-item-info create_link"
                           data-toggle="modal" data-target="#create_link">
                            <span class="glyphicon glyphicon-plus" aria-hidden="true"></span> 新增 (add)
                        </a>

                        <a href="javascript: void 0;" class="list-group-item list-group-item-info destroy_checked">
                            <span class="glyphicon glyphicon-trash" aria-hidden="true"></span> 删除 (destroy)
                        </a>

                        <a href="javascript: void 0;" class="list-group-item list-group-item-info sort_link">
                            <span class="glyphicon glyphicon-refresh" aria-hidden="true"></span> 排序 (sort)
                        </a>
                    </div>
                </div>
            </div>
        </div>
    </div>


    <!-- 新增Modal -->
    <div class="modal fade" id="create_link" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
        <div class="modal-dialog" role="document">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span
                            aria-hidden="true">&times;</span></button>
                    <h4 class="modal-title" id="myModalLabel">Modal title</h4>
                </div>
                <form class="form-horizontal" action="<?php echo U('store');?>" method="post">

                    <div class="modal-body">
                        <div class="form-group">
                            <label for="inputEmail3" class="col-sm-2 control-label">链接名称</label>
                            <div class="col-sm-10">
                                <input type="text" class="form-control" id="inputEmail3" name="name" placeholder="name">
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-2 control-label">网址</label>
                            <div class="col-sm-10">
                                <input type="text" class="form-control" name="url" id="url" >
                            </div>
                        </div>

                    </div>
                    <div class="modal-footer">
                        <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
                        <button type="submit" class="btn btn-primary">新 增</button>
                    </div>
                </form>

            </div>
        </div>
    </div>


    <!-- 编辑Modal -->
    <div class="modal fade" id="edit_link" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
        <div class="modal-dialog" role="document">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span
                            aria-hidden="true">&times;</span></button>
                    <h4 class="modal-title" id="">编辑链接</h4>
                </div>
                <form class="form-horizontal" action="<?php echo U('update');?>" method="post">

                    <input type="hidden" name="id" id="edit_id">
                    <div class="modal-body">
                        <div class="form-group">
                            <label for="" class="col-sm-2 control-label">链接名称</label>
                            <div class="col-sm-10">
                                <input type="text" value="<?php echo ($link["name"]); ?>" class="form-control" name="name" id="edit_name" placeholder="name">
                            </div>
                        </div>
                        <div class="form-group">
                            <label for="" class="col-sm-2 control-label">网址</label>
                            <div class="col-sm-10">
                                <input type="text" value="<?php echo ($link["url"]); ?>"  class="form-control" name="url" id="edit_url" placeholder="url">
                            </div>
                        </div>

                    </div>
                    <div class="modal-footer">
                        <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
                        <button type="submit" class="btn btn-primary">修 改</button>
                    </div>
                </form>

            </div>
        </div>
    </div>

</div>
<script src="/Public/js/jquery.min.js"></script>

<script src="/Public/bootstrap/js/bootstrap.min.js"></script>


    <script>
        $(function () {
            $(".edit").click(function () {
                var $tr = $(this).parents("tr");
                var name = $tr.children(".name").text();
                var url = $tr.children(".url").text();
                var id = $(this).data("id");

                $("#edit_name").val(name);
                $("#edit_url").val(url);
                $("#edit_id").val(id);
            })


            $("#check_all").click(function () {
                //所有checkbox跟着全选的checkbox走。
                $('.delete_checked').prop("checked", this.checked);
            });
            $(".destroy_checked").click(function() {
                var len = $(".delete_checked:checked").length;
                if (len == 0) {
                    alert("您必须至少选择一条");
                    return false;
                }
                $("#form").attr("action", "<?php echo U('destroy_checked');?>").submit();
            })
            $(".sort_link").click(function(){
                $("#form").attr("action","<?php echo U('sort_link');?>").submit();
            })
        })

    </script>


</body>
</html>